/*
 * EstrategiaCrearHerencia.java
 * 
 * Copyright (C) 2008 David Castellanos Serrano
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package dpoo.control.comportamiento;

import dpoo.figuras.estadoclase.EstadoClaseNormal;
import dpoo.figuras.estadoclase.EstadoClaseDestinoHerencia;
import dpoo.control.Control;
import dpoo.figuras.*;

import java.awt.event.MouseEvent;

public class EstrategiaCrearHerencia implements Estrategia {

    Control uniqueInstance = Control.instance();
    FiguraClase origenHerencia = null;

    public void claseMouseClicked(FiguraClase clase) {
        
        if(this.origenHerencia == null) {
            this.origenHerencia = clase;
            
            //pongo la decoración de la herencia
            this.origenHerencia.setEstado(new EstadoClaseDestinoHerencia());
            this.origenHerencia.repaint();
        } else {
            //quito la decoración de la herencia
            this.origenHerencia.setEstado(new EstadoClaseNormal());
            this.origenHerencia.repaint();
            //creo la FiguraHerencia y la almaceno
            FiguraHerencia herencia = new FiguraHerencia(this.origenHerencia, clase);
            this.uniqueInstance.addHerencia(herencia);
            this.origenHerencia = null;
        }
    }

    public void claseMouseEntered(FiguraClase clase) {
        clase.setEstado(new EstadoClaseDestinoHerencia());
        clase.repaint();
    }

    public void claseMouseExited(FiguraClase clase) {
        if(this.origenHerencia != clase) {
            clase.setEstado(new EstadoClaseNormal());
            clase.repaint();
        }
    }
    
    public void ventanaPrincipalMouseClicked(MouseEvent evt) {}

    public void ventanaPrincipalMouseDragged(MouseEvent evt) {}
}

